package whlogger.launcher.loginfields.views;

import whlogger.launcher.loginfields.views.controller.LogInJPanelController;
import whlogger.launcher.loginfields.views.repositories.BehaviorRepository;
import whlogger.launcher.loginfields.views.repositories.ListenerRepository;

/**
 *
 * @author d3rbastl3r
 */
public class LogInJPanel extends javax.swing.JPanel {
    private LogInJPanelController controller;
    
    /**
     * Creates new form LogInJPanel
     */
    public LogInJPanel(LogInJPanelController controller){
        this.controller = controller;
        
        initComponents();
        initComponentsBehavior();
		initComponentsListener();
    }
    
	/**
	 * Initialisiert die Listener der einzelnen Komponente des JPanels
	 */
    private void initComponentsListener(){
        ListenerRepository repository = new ListenerRepository();
		
		repository.initLoginJButtonActionListener(
			this.controller,
			this.nicknameJTextField,
			this.passwordJPasswordField
		);
		this.loginJButton.addActionListener(repository.getLoginJButtonActionListener());
		
		repository.initRegisterJButtonActionListener(
			this.controller
		);
		this.registerJButton.addActionListener(repository.getRegisterJButtonActionListener());
		
		this.controller.setListenerRepository(repository);
    }
    
    /**
     * Initialisiert das Verhalten der einzelnen Komponente des JPanels.
     */
    private void initComponentsBehavior(){
        BehaviorRepository repository = new BehaviorRepository();
        
        repository.initNicknameBehavior(this.nicknameJTextField);
        repository.initPasswordBehavior(this.passwordJPasswordField);
		repository.initLoginBehavior(this.loginJButton);
        
        this.controller.setBehaviorRepository(repository);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nicknameJTextField = new javax.swing.JTextField();
        passwordJPasswordField = new javax.swing.JPasswordField();
        loginJButton = new javax.swing.JButton();
        registerJButton = new javax.swing.JButton();

        setMinimumSize(new java.awt.Dimension(100, 50));
        setPreferredSize(new java.awt.Dimension(800, 50));
        setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 5, 10));

        nicknameJTextField.setForeground(new java.awt.Color(204, 204, 204));
        nicknameJTextField.setText("Name");
        nicknameJTextField.setToolTipText("");
        nicknameJTextField.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 102, 102)));
        nicknameJTextField.setDoubleBuffered(true);
        nicknameJTextField.setMinimumSize(new java.awt.Dimension(120, 20));
        nicknameJTextField.setPreferredSize(new java.awt.Dimension(120, 20));
        add(nicknameJTextField);

        passwordJPasswordField.setForeground(new java.awt.Color(204, 204, 204));
        passwordJPasswordField.setText("Password");
        passwordJPasswordField.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 102, 102)));
        passwordJPasswordField.setDoubleBuffered(true);
        passwordJPasswordField.setEchoChar('\u0000');
        passwordJPasswordField.setMinimumSize(new java.awt.Dimension(120, 20));
        passwordJPasswordField.setPreferredSize(new java.awt.Dimension(120, 20));
        add(passwordJPasswordField);

        loginJButton.setText("Log In");
        loginJButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 2, 2, 2));
        loginJButton.setDoubleBuffered(true);
        loginJButton.setEnabled(false);
        loginJButton.setMaximumSize(new java.awt.Dimension(63, 23));
        loginJButton.setMinimumSize(new java.awt.Dimension(63, 23));
        loginJButton.setPreferredSize(new java.awt.Dimension(63, 23));
        add(loginJButton);

        registerJButton.setText("Register");
        registerJButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 2, 2, 2));
        registerJButton.setDoubleBuffered(true);
        registerJButton.setMaximumSize(new java.awt.Dimension(63, 23));
        registerJButton.setMinimumSize(new java.awt.Dimension(63, 23));
        registerJButton.setPreferredSize(new java.awt.Dimension(63, 23));
        add(registerJButton);
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton loginJButton;
    private javax.swing.JTextField nicknameJTextField;
    private javax.swing.JPasswordField passwordJPasswordField;
    private javax.swing.JButton registerJButton;
    // End of variables declaration//GEN-END:variables
}
